from datetime import datetime
from peewee import (
    Model,
    AutoField,
    IntegerField,
    CharField,
    BooleanField,
    TextField,
    DoubleField,
    ForeignKeyField,
    MySQLDatabase,
    DateTimeField,
)
import mxupy as mu
import bigOAINet as bigo

# --- 核心任务表 ---


class ImageGenerateTask(mu.EntityX):
    """AI绘画核心任务表 (最终版)"""

    imageGenerateTaskId = AutoField()
    name = CharField(null=True, max_length=255)

    # --- 外键关联 ---
    user = ForeignKeyField(
        bigo.User, backref="tasks", on_delete="CASCADE", column_name="userId"
    )

    # --- 任务类别，对应json文件 ---
    workflowType = CharField(max_length=100)

    # --- 核心参数 ---
    positivePrompt = TextField(null=True)
    negativePrompt = TextField(null=True)
    width = IntegerField(default=512)
    height = IntegerField(default=768)
    seed = CharField(default="42", max_length=20)

    # 不足，还得加

    # [已加回] 批量生图的数量
    batch_size = IntegerField(default=1)

    extraParams = TextField(null=True)

    # 多张输入图，分号分隔
    inputImages= TextField(null=True)

    # 输出图
    outputImage=CharField(max_length=255)

    # --- 任务管理 ---
    status = CharField(default="pending", max_length=50)
    addTime = DateTimeField(default=datetime.now)
    finishTime = DateTimeField(null=True)

    class Meta:
        database = bigo.db
        name = "AI绘画任务"